<template>
  <n-layout-header>
    <div class="navbar navbar-wrapper">
      <n-space justify="space-between" align="center" style="width: 100%;">
        <n-space>
          <n-button class="navbar-brand" text @click="ToHome">API-Cloud</n-button>
          <n-button  class="navbar-brand" text @click="toInterfaceListPage" >接口大全</n-button>
          <n-button class="navbar-brand" text @click="handleClickGitMainPage" >git主页</n-button>
          <n-button class="navbar-brand" text @click="() => (window.location.href = '/messageboard')">留言板</n-button>
          <n-button class="navbar-brand" text @click="() => (window.location.href = '/duty')">免责声明</n-button>
        </n-space>
        <n-space>
          <n-input v-model:value="keyword" placeholder="接口搜索" class="search-input" />
          <n-button type="primary" @click="search" class="search-button">搜索</n-button>
          <UserAvatar></UserAvatar>
        </n-space>
      </n-space>
    </div>
  </n-layout-header>
</template>

<script>
import { ref } from 'vue';
import { NButton, NInput, NSpace, NLayoutHeader } from 'naive-ui';
import UserAvatar from '@/components/user/UserAvatar.vue'
import { useRouter } from 'vue-router'

export default {
  components: {
    UserAvatar,
    NButton,
    NInput,
    NSpace,
    NLayoutHeader
  },
  setup() {
    const keyword = ref('');
    const router = useRouter();

    const ToHome = ()=>{
      router.push("/home");
    }

    const search = () => {
      if (keyword.value) {
        router.push({ path: '/interface/search', query: { keyword: keyword.value } });
      } else {
        alert('请输入关键字');
      }
    };
    const handleClickGitMainPage = function(){
      window.location.href = 'https://gitee.com/shungen/projects?sort=&scope=&state=public';
    }

    const toInterfaceListPage = function(){
      router.push({ path: '/home', hash: '#interface-list' })
    }

    return {
      ToHome,
      keyword,
      search,
      toInterfaceListPage,
      handleClickGitMainPage
    };
  }
};
</script>

<style scoped>
.navbar {
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #333;
  color: #fff;
}

.navbar n-button {
  color: #fff;
  font-size: 16px;
}

.search-input {
  width: 200px;
}

.search-button {
  background-color: #00ADEF;
  border-color: #00ADEF;
}
</style>
